package net.comm.shequ.db;

import org.sakaiproject.db.api.iServiceSql;


/**
 * methods for accessing user data in a database.
 */
public class WyServeServiceSqlMysql implements iServiceSql
{
	/**
	 * 返回根据主键删除语句
	 */
	public String getDeleteSql()
	{
		return "delete from WyServe where SeqID=? and FollID=?";
	}

	/**
	 * 返回插入语句
	 */
	public String getInsertSql()
	{
		return "insert into WyServe (  seqID,  follID,  wuyeID,  ntype, title,  content,  f_ID," +
				" status,  attachcnt,  replycnt,  userID, IP,  mtime  )" +
				" values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
	}
	
	/**
	 * 返回根据主键修改语句
	 */
	public String getUpdateSql()
	{
		return "update WyServe  set wuyeID=?,  ntype=?, title=?,  content=?,  f_ID=?," +
				" status=?,  attachcnt=?,  replycnt=?,  userID=?, IP=?,  mtime=? " +
				" where  SeqID=? and FollID=?";
	}

	/**
	 * 返回根据主键修改语句
	 */
	public String getUpdstsSql()
	{
		return "update WyServe  set  status=?,  attachcnt=?,  replycnt=? " +
				" where  SeqID=? and FollID=?";
	}

	/**
	 * 返回根据主键修改语句
	 */
	public String getUpdAttachReplycntSql()
	{
		return "update WyServe  set status=?,  attachcnt=?,  replycnt=? " +
				" where  SeqID=? and FollID=? ";
	}

	/**
	 * 返回根据主键查询语句
	 */
	public String getbykeySql()
	{
		return "select seqID,  follID,  wuyeID,  ntype, title,  content,  f_ID," +
				" status,  attachcnt,  replycnt,  userID, IP,  mtime " +
				" from WyServe where SeqID=? and FollID=?";
	}
	
	/**
	 * 返回根据主键查询语句
	 */
	public String getMaxFollIDSql()
	{
		return "select seqID,  follID,  wuyeID,  ntype, title,  content,  f_ID," +
				" status,  attachcnt,  replycnt,  userID, IP,  mtime " +
				" from WyServe where SeqID=? order by FollID desc ";
	}

	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecbyPageSql()
	{
	
		StringBuffer sb =  new StringBuffer("select seqID,  follID,  wuyeID,  ntype, title,  content,  f_ID," +
				" status,  attachcnt,  replycnt,  userID, IP,  mtime ");
		sb.append(" from WyServe ");
		sb.append(" where wuyeID=? and follID = 0 Order by mtime desc ");
		sb.append(" limit ?,? ");
				
		return sb.toString();	
	}	
	
	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecCommentbyPageSql()
	{
	
		StringBuffer sb =  new StringBuffer("select seqID,  follID,  wuyeID,  ntype, title,  content,  f_ID," +
				" status,  attachcnt,  replycnt,  userID, IP,  mtime ");
		sb.append(" from WyServe ");
		sb.append(" where seqID=? and follID > 0 Order by follID ");
		sb.append(" limit ?,? ");
				
		return sb.toString();	
	}	
	
	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecSql()
	{
	
		StringBuffer sb =  new StringBuffer("select seqID,  follID,  wuyeID,  ntype, title,  content,  f_ID," +
				" status,  attachcnt,  replycnt,  userID, IP,  mtime ");
		sb.append(" from WyServe ");
				
		return sb.toString();	
	}
	
	/**
	 * 返回所有记录数
	 */
	public String getCountSql1()
	{
		return "select count(*) as COUNT from WyServe ";
	}

	/**
	 * 返回根据查询条件的记录数
	 */
	public String getCountSql2()
	{
		return "select count(*) as COUNT from WyServe where wuyeID=? and follID = 0 ";
	}

	/**
	 * 返回所有记录数
	 */
	public String getCountSql3()
	{
		return "select count(*) as COUNT from WyServe where seqID=? and follID > 0 ";
	}

	/**
	 * @see net.comm.job.db.iServiceSql.impl.UserServiceSql#getMaxInputsForSelectWhereInQueries()
	 */
	public int getMaxInputsForSelectWhereInQueries() {
		// For Oracle, the maximum supported number of expressions in a list is 1000. 
		return 1000;
	}
}
